<template>
	<view class="container">
		<view v-if="contentList.length==0" style="text-align: center;margin: 20rpx;">
			<text style="font-size: 35rpx;font-weight: bold;">暂无数据</text>
		</view>
		<view v-for="item in contentList" class="card" @click="goDetail(item.id)">
			<uni-section  type="line">
				<uni-card :title="item.name" :isFull="true" :sub-title="item.categoryName" :extra="item.bookName" :thumbnail="avatar">
					<text class="uni-body">{{item.desc}}</text>
					<image :src="item.imagePath" style="height: 200rpx;" mode="aspectFit"></image>
					<view style="margin: 10rpx;">{{item.username}}</view>
					<view v-if="userId!=0 && userId!=null">
					<view :style="item.auditStatus==3?'background-color: #3bf551;':(item.auditStatus==1?'background-color: #c3b5bb;':'background-color: #ff4f4f;')" class="statusStyle">
						{{item.auditStatusValue}}
						
					</view>
					<view v-if="item.auditStatus!=3">
						<view style="float: right;" class="button" @click.native.stop="updateBook(item.id)">重新编辑</view>
						<view style="float: right;" class="button" @click.native.stop="deleteBook(item.id)">删除</view>
					</view>
					</view>
				</uni-card>
			</uni-section>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app"
	import {
		ref
	} from "vue";
	import {
		baseUrl
	} from "../../static/js/util.js"

	let search = ref('')
	let type = ref(1)
	let contentList = ref([])
	let pageSize = 10;
	let pageNo = 1;
	let categoryId=ref(0)
	let userId=ref(0)
	let authorization = localStorage.getItem("Authorization")
	
	function goDetail(bookId){
		uni.navigateTo({
			url:'/pages/bookCategory/bookCategory?id='+bookId
		})
	}
	
	function updateBook(id){
		uni.navigateTo({
			url:'/pages/add/addBook?bookId='+id
		})
	}
	
	function deleteBook(id){
		uni.showModal({
		    title: '提示',
		    content: '确定删除这本书吗',
		    success: function (res) {
		        if (res.confirm) {
		            let params = {
		            	id:id
		            }
		            
		            uni.request({
		            	url: baseUrl + "/book/delete",
		            	method: 'GET',
		            	header: {
		            		'Authorization': authorization
		            	},
		            	data: params,
		            	success: res => {
		            		requestSearch()
		            	}
		            })
		        } else if (res.cancel) {
		            
		        }
		    }
		});

	}


	function requestSearch() {
		let params = {
			pageNo,
			pageSize,
			userId:userId.value
		}
		console.log(params)
		uni.request({
			url: baseUrl + "/book/list",
			header: {
				'Authorization': authorization
			},
			method: 'POST',
			data: params,
			success: res => {
				contentList.value = res.data.data.result
			}
		})
	}
	

	onLoad(option => {
		userId.value=option.userId
	})
	onShow(() => {
		requestSearch()
	})
</script>

<style lang="scss" scoped>
	.card {
		margin: 20rpx;
		border: 1px solid #eee;
		padding-bottom: 100rpx;
	}
	.statusStyle{
		width: 100rpx;
		text-align: center;
		border: 3px solid #cfcfcf;
		color: #ffffff;
	}
	.button{
		border: 1px solid black;
		font-size: 30rpx;
		width: max-content;
		padding: 10rpx;
		text-align: center;
		margin: 20rpx;
	}
</style>